/**
 * 产品修改js
 */
var comValidform=null;
var returnStatus=false;
var agreementUpdate={
	agreementUE:null,
	key:null,
		
	startEvent:function(){
		 
		$("#recordTab ul").idTabs();
		agreementUpdate.agreementUE = UE.getEditor('agreement',{
			initialFrameHeight:340,
			initialFrameWidth:898
		});
		
		 
		agreementUpdate.showInfo();
		
		comValidform=$(".com-addForm").Validform({
			datatype:{
				"m0-2" : /^[0-9]+(.[0-9]{1,2})?$/
			},
			tiptype:2,
			tipSweep:true,
			beforeSubmit:function(curform){
				var url = 'mgr/agreementCtrl/update';
				var params = jsUtils.serializeJson($('.com-addForm'));
				var agreement = agreementUpdate.agreementUE.getContent();
				params.agreement=agreement;
				
				var cb = function(data){

					//成功返回
					if(data.resultCode==200){
						alert("已保存，如上传了新图片文件，请联系技术部处理才能在APP中正常显示！");
						localStorage.removeItem(agreementUpdate.key);
						//关闭窗口并刷新数据
						returnStatus=true;
					}else{
						alert(data.msg);
					}
				};
				sendApiNoLoadSync(url, params, cb, 'POST');
				return returnStatus;
			}
		});
	},
	
	showInfo:function(){
		
		var id = art.dialog.data('updId');
		agreementUpdate.key = id + "_Agreement_Key";
		agreementInfo = eval('(' + localStorage.getItem(agreementUpdate.key) + ')');
		$("input[name='id']").val(agreementInfo.id);
		$("input[name='name']").val(agreementInfo.name);
		$("input[name='cts']").val(agreementInfo.cts);
		$("input[name='creater']").val(agreementInfo.creater);
		$("input[name='type']").val(agreementInfo.type);
		$("textarea[name='argDesc']").val(agreementInfo.argDesc);
		if(agreementInfo.agreementText != null){
			agreementUpdate.agreementUE.ready(function() {
				agreementUpdate.agreementUE.setContent(agreementInfo.agreementText);
            });
		}
	},
	
	init:function(){
		agreementUpdate.startEvent();
	}
}
$(document).ready(function() {
	agreementUpdate.init();
});
function submitForm(){
	comValidform.submitForm();
	return returnStatus;
}